﻿/*
SINACOR - BMF&Bovespa
Arquivo: Exportacao.cs
Criado em: 28-jun-2010 08:28:56
Arquiteto Responsável: p-wgeneroso
*/
using System;
using System.Collections.Generic;
using System.Text;
using PSE.ProcessManager.Common.Gateway;
using PSE.ProcessManager.Common.Process;
using Sinacor.Infra.Core.ProcessManager.Client;
using Sinacor.Infra.Common.Exceptions;
using Sinacor.Infra.Service.ExceptionHandling;
using Sinacor.Infra.Common.Validation;


namespace Sinacor.Process.Bovespa.Alocacao.Client 
{
	public class Exportacao : SinacorBaseProcessClient 
	{
		#region Construtor

		public Exportacao()
		{
            this.Id = ProcessEntity.Catalog.Exportacao.ProcessID;
		}

		#endregion

		#region Eventos

        public event EventHandler<ProcessEventArgs<ProcessEntity.ExportacaoResultado>> ExportacaoConcluida;

		#endregion

		#region Métodos

		/// <summary>
        /// Exportar Alocacao
		/// </summary>
		/// <param name="entity"></param>
		public void ExportarAlocacao(ProcessEntity.Parameter.FiltroExportacaoAlocacao entity)
		{
            Message<ProcessEntity.Parameter.FiltroExportacaoAlocacao> message = new Message<ProcessEntity.Parameter.FiltroExportacaoAlocacao>();

            message.MessageId = ProcessEntity.Catalog.Exportacao.ExportarAlocacao.MessageID;
            message.ProcessId = this.Id;
            message.Parameter = entity;
            message.Operation = ProcessEntity.Catalog.Exportacao.ExportarAlocacao.Operation;
            message.From = "ExportarAlocacao";

            this.BeginSendMessage(message);
		}

		/// <summary>
        /// OnMessageReceived
		/// </summary>
		/// <param name="message"></param>
		protected override void OnMessageReceived(BaseMessage message)
		{
            if (message.MessageId == ProcessEntity.Catalog.Exportacao.ExportacaoConcluida.MessageID
                && ExportacaoConcluida != null)
            {
                ExportacaoConcluida(this, new ProcessEventArgs<ProcessEntity.ExportacaoResultado>(message.RetrieveParameter<ProcessEntity.ExportacaoResultado>()));
            }
            else
                base.OnMessageReceived(message);
		}

		#endregion
	}

}